package cn.dujc.superkid.adapter;

import android.support.annotation.Nullable;

import java.util.List;

import cn.dujc.core.adapter.BaseAdapter;
import cn.dujc.core.adapter.BaseViewHolder;
import cn.dujc.core.adapter.util.MultiTypeDelegate;
import cn.dujc.superkid.R;
import cn.dujc.superkid.bean.VideoListResult;

/**
 * @author du
 * date 2018/8/4 下午4:11
 */
public class CourseCatalogueAdapter extends BaseAdapter<Object> {

    public CourseCatalogueAdapter(@Nullable List<Object> data) {
        super(data);
        final MultiTypeDelegate<Object> delegate = new MultiTypeDelegate<Object>() {
            @Override
            protected int getItemType(Object o) {
                return o instanceof String ? R.layout.item_subtitle_text : R.layout.item_single_text;
            }
        };
        delegate.registerItemType(R.layout.item_subtitle_text, R.layout.item_subtitle_text)
                .registerItemType(R.layout.item_single_text, R.layout.item_single_text);
        setMultiTypeDelegate(delegate);
    }

    @Override
    protected void convert(BaseViewHolder helper, Object item) {
        if (item instanceof String) {
            helper.setText(R.id.item_tv_text, (String) item);
        } else if (item instanceof VideoListResult.VideoEntity){
            helper.setText(R.id.item_tv_text, ((VideoListResult.VideoEntity) item).getVideo_title());
        } else if (item instanceof VideoListResult.ExaminationEntity){
            helper.setText(R.id.item_tv_text, ((VideoListResult.ExaminationEntity) item).getExamination_title());
        }
    }
}
